#include "smart_home.h"
#include "device.h"
#include "vipaccount.h"


manager_t *manager_device=NULL;
manager_user_t *manager_account=NULL;
char cur_AccountNumber[10]={'0'};
int cur_AccountGrade=1;
bool signup_flag=false;
int max_value = 100;

//基本信息初始化
void basic_info_init()
{
    static volatile bool print_lock=false;
    if(print_lock)  return;
    printf("[DEBUG] basic_info_init() called\n");
    manager_device=createDoublyCircularLinkedList_manager();
    if(manager_device==NULL)
    {
        perror("manager_device create error!\n");
        return;
    }
    manager_account=createDoubleCircularLinkedList_ANmanager();
    DoubleCircularLinkedList_Push(manager_device, 1,"led","led_device",false);
    DoubleCircularLinkedList_Push(manager_device, 2,"temp","temp_device",false);
    DoubleCircularLinkedList_Push(manager_device, 3,"currtain","currtain_device",false);
    DoubleCircularLinkedList_Push(manager_device, 4,"safe","safe_device",false);

    InsertDoubleCircularLinkedList_ANnode(manager_account, "hry123", "123456",3);
    InsertDoubleCircularLinkedList_ANnode(manager_account, "hry666", "123456",2);
    InsertDoubleCircularLinkedList_ANnode(manager_account, "hry999", "123456",1);

    DoubleCircularLinkedList_Print(manager_device);
    print_lock=true;
    printf("[INIT] === DONE ===\n");
}

// //首页操作
// void on_login_page_handler()
// {
//     basic_info_init();
//     user_t *user_pos=manager_device;
//     while(user_pos)
//     {
//         if(strcmp(lv_textarea_get_text(ui_TextAreaAccount),user_pos->In_AccountNumber)==0 && strcmp(lv_textarea_get_text(ui_TextAreaPassword),user_pos->In_Password)==0)
//         {
//             //按键ui_ButtonSignUp就允许触发事件
//             //  验证成功 - 启用登录按钮
//             lv_obj_clear_state(ui_ButtonSignUp, LV_STATE_DISABLED); // 清除禁用状态
//             lv_obj_add_flag(ui_ButtonSignUp, LV_OBJ_FLAG_CLICKABLE); // 设置为可点击
//             lv_obj_set_style_opa(ui_ButtonSignUp, LV_OPA_COVER, 0); // 恢复不透明度           
//         }
//         else
//         {
//             //按键ui_ButtonSignUp就不允许触发事件
//             //  验证失败 - 禁用登录按钮
//             lv_obj_add_state(ui_ButtonSignUp, LV_STATE_DISABLED); // 添加禁用状态
//             lv_obj_clear_flag(ui_ButtonSignUp, LV_OBJ_FLAG_CLICKABLE); // 设置为不可点击
//             lv_obj_set_style_opa(ui_ButtonSignUp, LV_OPA_50, 0); // 设置半透明效果
//         }
//         user_pos=user_pos->next;
//     }
    
//     if(user_pos == NULL) {
//         //  确保按钮保持禁用状态
//         lv_obj_add_state(ui_ButtonSignUp, LV_STATE_DISABLED);
//     }
// }